package com.weather.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weather.common.core.domain.R;
import com.weather.pojo.entity.Area;
import com.weather.pojo.entity.City;
import com.weather.pojo.entity.Province;
import com.weather.pojo.entity.Street;
import com.weather.service.IAreaService;
import com.weather.service.ICityService;
import com.weather.service.IProvinceService;
import com.weather.service.IStreetService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/location")
@Api(tags = "地理位置")
public class LocationController {

    // 一级地理位置
    @Resource
    private IProvinceService provinceService;
    // 二级地理位置
    @Resource
    private ICityService  cityService;

    // 三级地理位置
    @Resource
    private IAreaService  areaService;

    // 四级地理位置
    @Resource
    private IStreetService streetService;

    @ApiOperation("获取所有一级地理位置")
    @GetMapping("/getProvince")
    public R<List<Province>> getProvince(){
        return R.ok(provinceService.list());
    }

    @ApiOperation("获取所有二级地理位置")
    @GetMapping("/getCity/{provinceId}")
    public R<List<City>> getCity(@PathVariable("provinceId") Integer provinceId){
        return R.ok(cityService.list(new QueryWrapper<City>().eq("pid", provinceId)));
    }

    @ApiOperation("获取所有三级地理位置")
    @GetMapping("/getArea/{cityId}")
    public R<List<Area>> getArea(@PathVariable("cityId") Integer cityId){
        return R.ok(areaService.list(new QueryWrapper<Area>().eq("pid",  cityId)));
    }

    @ApiOperation("获取所有四级地理位置")
    @GetMapping("/getStreet/{areaId}")
    public R<List<Street>> getStreet(@PathVariable("areaId") Integer areaId){
        return R.ok(streetService.list(new QueryWrapper<Street>().eq("pid", areaId)));
    }
}

